import Scanner from "./Scanner";
import nestTokens from "./nestTokens";

export default function parseTemplateTotokens(templateStr){
    let scanner =   new Scanner(templateStr);
    let tokens = [];
    var words = '';
    while(!scanner.eos() ){
        words =    scanner.scanUtil("{{")
        if(words != ''){
            tokens.push(['text',words])

        }
        scanner.scan("{{");
        words =  scanner.scanUtil('}}');
        scanner.scan("}}")
        if(words){
            if(words[0] == '#'){
                tokens.push(['#',words.substring(1)])
            }else if(words[0] == '/'){
                tokens.push(['/',words.substring(1)])
            }else{
                tokens.push(['name',words])

            }

        }
    }
    return nestTokens(tokens);
} 